Added an example of how to use GDK_MODIFIER_MASK to test for modifier keys
authorFederico Mena Quintero <federico@ximian.com>
Mon, 16 Feb 2004 19:00:16 +0000 (19:00 +0000)
committerFederico Mena Quintero <federico@src.gnome.org>
Mon, 16 Feb 2004 19:00:16 +0000 (19:00 +0000)
2004-02-16  Federico Mena Quintero  <federico@ximian.com>

* gdk/tmpl/windows.sgml: Added an example of how to use
GDK_MODIFIER_MASK to test for modifier keys correctly.

* gtk/migrating-checklist.sgml: Likewise.

docs/reference/ChangeLog
docs/reference/gtk/migrating-checklist.sgml

index 9478a875ee6fd215e6ef91eae25c09b784b0c6fc..a049d527a9384952e29ca73af2b6b324f4749965 100644 (file)
@@ -3,6 +3,8 @@
        * gdk/tmpl/windows.sgml: Added an example of how to use
        GDK_MODIFIER_MASK to test for modifier keys correctly.
 
+       * gtk/migrating-checklist.sgml: Likewise.
+
 Sun Feb 15 23:51:08 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/tmpl/gtkcomboboxentry.sgml: 
index 08eba65c8b9ccc8d1620ff1e3871fbe118a42e2e..9c83a7030a903823cd8de961977faaf9de5816a9 100644 (file)
@@ -210,6 +210,54 @@ my_widget_expose_event_handler (GtkWidget *widget, GdkEventExpose *event)
 }
     </programlisting>
   </section>
+
+  <section id="checklist-modifiers">
+    <title>Test for modifier keys correctly</title>
+
+    <formalpara>
+      <title>Why</title>
+      <para>
+       With <constant>GDK_MODIFIER_MASK</constant> you can test for
+       modifier keys reliably; this way your key event handlers will
+       work correctly even if <keycap>NumLock</keycap> or
+       <keycap>CapsLock</keycap> are activated.
+      </para>
+    </formalpara>
+
+    <para>
+      In a <structname>GdkEventKey</structname>, the
+      <structfield>state</structfield> field is a bit mask which
+      indicates the modifier state at the time the key was pressed.
+      Modifiers are keys like <keycap>Control</keycap>, and
+      <keycap>NumLock</keycap>.  When implementing a <link
+      linkend="GtkWidget-key-press-event">GtkWidget::key_press_event</link>
+      handler, you should use the
+      <constant>GDK_MODIFIER_MASK</constant> constant to test against
+      modifier keys.  This value encompasses all the modifiers which
+      the user may be actively pressing, such as
+      <keycap>Control</keycap> and <keycap>Shift</keycap>, but ignores
+      "inocuous" modifiers such as <keycap>NumLock</keycap> and
+      <keycap>CapsLock</keycap>.  The following example tests for
+      <keycombo>
+      <keycap>Control</keycap><keycap>F10</keycap></keycombo> being
+      pressed.
+    </para>
+
+    <programlisting id="GDK_MODIFIER_MASK">
+static gboolean
+my_widget_key_press_handler (GtkWidget *widget, GdkEventKey *event)
+{
+  if (event-&gt;keysym == GDK_F10
+      &amp;&amp; (event-&gt;state &amp; GDK_MODIFIER_MASK) == GDK_CONTROL_MASK)
+    {
+      g_print ("Control-F10 was pressed\n");
+      return TRUE;
+    }
+
+  return FALSE;
+}
+    </programlisting>
+  </section>
 </chapter>
 
 <!--